﻿using CefSharp;
using CefSharp.WinForms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyCef.service
{
    public class MyKeyEvent
    {
        private volatile static bool IsDevToolShow = false;
        private volatile static bool IsFullScreen = false;
        public static void DoKeyEvent(Form form, KeyEventArgs e, ChromiumWebBrowser browser)
        {
            switch (e.KeyCode)
            {
                case Keys.F12:
                    MyKeyEvent.ChangeDevTools(form, e, browser);
                    break;
                case Keys.F11:
                    MyKeyEvent.ChangeWindow(form, e, browser);
                    break;
                default:
                    break;
            };
        }

        private static void ChangeDevTools(Form form, KeyEventArgs e, ChromiumWebBrowser browser)
        {
            if (IsDevToolShow)
            {
                browser.CloseDevTools();
            }
            else
            {
                browser.ShowDevTools();
            }
        }

        private static void ChangeWindow(Form form, KeyEventArgs e, ChromiumWebBrowser browser)
        {
            IsFullScreen = !IsFullScreen;
            Control[] ps = form.Controls.Find("topPanel", true);
            Control p = ps[0];
            if (IsFullScreen)
            {
                form.FormBorderStyle = FormBorderStyle.None;
                form.WindowState = FormWindowState.Maximized;
            }
            else
            {
                form.FormBorderStyle = FormBorderStyle.Sizable;
            }
            p.Visible = !IsFullScreen;
        }
    }
}
